package com.common.www.bean.entity.auth;

import org.springframework.boot.base.jpa.domain.entity.NumberIdentityEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;


/**
 * 字典表
 */
@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = {"createTime","lastUpdateTime"})
public class Dict  extends NumberIdentityEntity {

    @JsonIgnoreProperties(value = {"parent", "children",})
    @ManyToOne()
    @JoinColumn(name = "parent")
    private Dict parent;

    //具体数据
    @JsonIgnoreProperties(value = {""})
    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parent")
    @OrderBy("sort asc")
    @Where(clause = "flag = 1")
    private List<Dict> children;

    /**
     * 字典名称
     */
    @Column(length = 128)
    private String name;
    /**
     * 字典值
     */
    @Column(length = 128)
    private String valueDict;
    /**
     * 字典key
     */
    @Column(length = 128)
    private String keyDict;


    /**
     * 排序数字大小，数字越小排列在越前面
     */
    @Column(length = 30)
    private Integer sort;
    /**
     * 节点等级
     */
    @Column(length = 30)
    private Integer level=1;
}
